<?php

/**
 * @package		JBS
 * @license		GNU/GPL, see LICENSE.php
 */

jimport('joomla.application.component.controller');

/**
 * JBSControllerAssetsGroups
 *
 * @package		JBS
 */

/*
Component Naming Convention:
<Component Name><Controller><Controller Name>
* */
class JBSControllerAssetGroups extends JController {
	/* constructor (registers additional tasks to methods)
	* @return void
	*/
	function __construct() {
		parent :: __construct();

		// Register Extra tasks
		$this->registerTask('add', 'edit');
//		$this->registerTask('ajaxGetAll', 'ajaxGetAll');
	}

	function display()
	{
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $VIEW_ASSETGROUPS, null, JText :: _('Vew Asset Groups').' - '.JText :: _('NO PERMISSION'))){
			return;
		}
		JRequest :: setVar('view', 'assetgroups');
		JRequest :: setVar('layout', 'list');

		parent::display();
	}

	/*
	 * AJAX Callback Function
	 *
	 * Get All Asset Groups
	 * */
	function ajaxGetAll(){
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $VIEW_ASSETGROUPS, null, JText :: _('Vew Asset Groups').' - '.JText :: _('NO PERMISSION'))){
			return;
		}
		JRequest :: setVar('view', 'assetgroups');
		JRequest :: setVar('layout', 'ajax_list');

		parent::display();
	}
	/**
	 * display the edit form
	 * @return void
	 */
	function edit() {
		$task = JRequest :: getVar('task');

		switch ($task) {
			case 'add':		//Check Add Permission
				if (!JBSRoles :: checkPermission($this, JBSConfig :: $ADD_ASSETGROUPS, 'index.php?option=com_jbschedule&controller=assetgroups', JText :: _('Add new Asset Groups').' - '.JText :: _('NO PERMISSION')))
					return;
				break;
			case 'edit':	//Check Edit Permission
				if (!JBSRoles :: checkPermission($this, JBSConfig :: $EDIT_ASSETGROUPS, 'index.php?option=com_jbschedule&controller=assetgroups', JText :: _('Edit Asset Groups').' - '.JText :: _('NO PERMISSION')))
					return;
				break;
		}

		JRequest :: setVar('view', 'assetgroups');
		JRequest :: setVar('layout', 'form');
		JRequest :: setVar('hidemainmenu', 1);

		parent :: display();
	}

	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	function save() {
		$model = $this->getModel('assetgroups');

		if ($model->store($post)) {
			$msg = JText :: _('SAVED');
		} else {
			$msg = JText :: _('NOT SAVED');
		}

		// Check the table in so it can be edited.... we are done with it anyway
		$link = 'index.php?option=com_jbschedule&controller=assetgroups';
		$this->setRedirect($link, $msg);
	}

	/**
	 * remove record(s)
	 * @return void
	 */
	function remove() {
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $DEL_ASSETGROUPS, 'index.php?option=com_jbschedule&controller=assetgroups', JText :: _('Delete Asset Groups').' - '.JText :: _('NO PERMISSION')))
			return;

		$model = $this->getModel('assetgroups');
		if (!$model->delete()) {
			$msg = JText :: _('NOT DELETED');
		} else {
			$msg = JText :: _('DELETED');
		}

		$this->setRedirect('index.php?option=com_jbschedule&controller=assetgroups', $msg);
	}

	/**
	 * cancel editing a record
	 * @return void
	 */
	function cancel() {
		$msg = JText :: _('CANCELED');
		$this->setRedirect('index.php?option=com_jbschedule&controller=assetgroups', $msg);
	}
}
?>
